<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar shadow">
        <!--搜索条件-->
        <div class="btn-group tool-button mt5">
            <el-input placeholder="用户名或昵称或手机号" v-model="pageForm.searchKeyword" @keyup.enter.native="pageData"
                      size="medium"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="daterange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    unlink-panels
                    align="right"
                    size="medium"
                    value-format="yyyy-MM-dd"
                    style="width: 400px">
            </el-date-picker>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                @sort-change='pageOrder'
                size="small"
                header-align="center"
                @selection-change="handleSelectionChange"
                style="width: 100%"
                show-summary
                :summary-method="getSumData"
                :default-sort="{prop: 'opAt', order: 'descending'}">

            <el-table-column
                    fixed="left"
                    label="日期"
                    header-align="left"
                    prop="date"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    fixed="left"
                    label="用户名"
                    header-align="left"
                    width="100"
                    prop="userName"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    fixed="left"
                    label="昵称"
                    header-align="left"
                    prop="nickName"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    fixed="left"
                    label="手机号"
                    header-align="left"
                    prop="phone"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="充值"
                    header-align="left"
                    prop="recharge"
                    :sortable="'custom'"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="转出"
                    header-align="left"
                    prop="cash"
                    :sortable="'custom'"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="礼物支出"
                    header-align="left"
                    prop="giftOrder"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="礼物收入"
                    header-align="left"
                    prop="giftIncome"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="系统礼物收入"
                    header-align="left"
                    prop="systemGiftIncome"
                    :sortable="'custom'"
                    width="140"
                    :show-overflow-tooltip="true">
                <template slot="header" slot-scope="scope">
                    <span>系统礼物收入</span>
                    <el-tooltip effect="light" placement="left" content="系统礼物收入 = 礼物支出 - 礼物收入">
                        <i class="el-icon-question" class="tips-icon"></i>
                    </el-tooltip>
                </template>
            </el-table-column>

            <el-table-column
                    label="球类下注"
                    header-align="left"
                    prop="ballBet"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="球注撤销"
                    header-align="left"
                    prop="ballRevert"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="球注结算"
                    header-align="left"
                    prop="ballResult"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="自身返利"
                    header-align="left"
                    prop="selfRebate"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="下级返水"
                    header-align="left"
                    prop="subRebate"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="系统返水支出"
                    header-align="left"
                    prop="systemRebatePay"
                    :sortable="'custom'"
                    width="140"
                    :show-overflow-tooltip="true">
                <template slot="header" slot-scope="scope">
                    <span>系统返水支出</span>
                    <el-tooltip effect="light" placement="left" content="系统返水支出 = 自身返利 + 下级返水">
                        <i class="el-icon-question" class="tips-icon"></i>
                    </el-tooltip>
                </template>
            </el-table-column>

            <el-table-column
                    label="游戏中心盈亏"
                    header-align="left"
                    prop="gameCenterIncome"
                    :sortable="'custom'"
                    width="140"
                    :show-overflow-tooltip="true">
                <template slot="header" slot-scope="scope">
                    <span>游戏中心盈亏</span>
                    <el-tooltip effect="light" placement="left" content="游戏中心盈亏 = 球类下注 - 球注撤销 - 球注结算 - 系统返水支出">
                        <i class="el-icon-question" class="tips-icon"></i>
                    </el-tooltip>
                </template>
            </el-table-column>

            <el-table-column
                    label="兑换"
                    header-align="left"
                    prop="exchange"
                    :sortable="'custom'"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="兑换退还"
                    header-align="left"
                    prop="exchangeBack"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="商品支出"
                    header-align="left"
                    prop="goodsPay"
                    :sortable="'custom'"
                    width="120"
                    :show-overflow-tooltip="true">
                <template slot="header" slot-scope="scope">
                    <span>商品支出</span>
                    <el-tooltip effect="light" placement="left" content="商品支出 = 兑换 - 兑换退还">
                        <i class="el-icon-question" class="tips-icon"></i>
                    </el-tooltip>
                </template>
            </el-table-column>

            <el-table-column
                    label="转账"
                    header-align="left"
                    prop="transfer"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="转账退还"
                    header-align="left"
                    prop="transferCancel"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="收款"
                    header-align="left"
                    prop="collect"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="购买观点"
                    header-align="left"
                    prop="buyViewPoint"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="出售观点"
                    header-align="left"
                    prop="sellViewPoint"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="观点退款"
                    header-align="left"
                    prop="refundViewPoint"
                    :sortable="'custom'"
                    width="100"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="观点退还"
                    header-align="left"
                    prop="returnViewPoint"
                    :sortable="'custom'"
                    width="120"
                    :show-overflow-tooltip="true">
                <template slot="header" slot-scope="scope">
                    <span>观点退还</span>
                    <el-tooltip effect="light" placement="left" content="因赛事重新结算导致的观点退款退还、出售观点退还">
                        <i class="el-icon-question" class="tips-icon"></i>
                    </el-tooltip>
                </template>
            </el-table-column>

            <el-table-column
                    label="系统观点收入"
                    header-align="left"
                    prop="systemViewPointIncome"
                    :sortable="'custom'"
                    width="140"
                    :show-overflow-tooltip="true">
                <template slot="header" slot-scope="scope">
                    <span>系统观点收入</span>
                    <el-tooltip effect="light" placement="left" content="系统观点收入 = 购买观点 - 出售观点 - 观点退款 + 观点退还（重新结算）">
                        <i class="el-icon-question" class="tips-icon"></i>
                    </el-tooltip>
                </template>
            </el-table-column>

            <el-table-column
                    label="(活动)自身消费返利"
                    header-align="left"
                    prop="activityCostRebate"
                    :sortable="'custom'"
                    width="150"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    label="(活动)邀请消费返利"
                    header-align="left"
                    prop="activityInviteRebate"
                    :sortable="'custom'"
                    width="150"
                    :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column
                    fixed="right"
                    label="创建时间"
                    header-align="center"
                    align="center"
                    width="120"
                    prop="ctAt">
                <template slot-scope="scope">
                    {{formatAt(scope.row.ctAt)}}
                </template>
            </el-table-column>
        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            return {
                searchDate: [],
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                pageForm: {
                    userType: "",
                    searchKeyword: "",
                    searchDate: "",
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "",
                    pageOrderBy: ""
                },
                sumMap: {
                    recharge: "",
                    cash: "",
                    giftOrder: "",
                    giftIncome: "",
                    systemGiftIncome: "",
                    ballBet: "",
                    ballRevert: "",
                    ballResult: "",
                    selfRebate: "",
                    subRebate: "",
                    systemRebatePay: "",
                    gameCenterIncome: "",
                    exchange: "",
                    exchangeBack: "",
                    goodsPay: "",
                    transfer: "",
                    transferCancel: "",
                    collect: "",
                    buyViewPoint: "",
                    sellViewPoint: "",
                    refundViewPoint: "",
                    returnViewPoint: "",
                    systemViewPointIncome: "",
                    activityCostRebate: "",
                    activityInviteRebate: ""
                },
                tableData: [],
                selectData: []
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                if (column.order === "descending") {
                    this.pageForm.pageOrderBy = "DESC";
                } else {
                    this.pageForm.pageOrderBy = "ASC";
                }
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                let self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                $.post(base + "/platform/user/account/statistics/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code === 0) {
                        self.tableData = data.data.pagination.list;
                        self.pageForm.totalCount = data.data.pagination.totalCount;
                        self.sumMap = data.data.sumMap;
                        self.$nextTick(() => {
                            document.querySelectorAll('.el-table__footer .cell').forEach(el => {
                                if (Number(el.innerText) < 0) el.style.color = 'red';
                            });
                        })
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            handleSelectionChange: function (val) {
                this.selectData = val;
            },
            getSumData: function (param) {
                const {columns, data} = param;
                const sums = [];
                columns.forEach((column, index) => {
                    if (index === 0) {
                        sums[index] = '合计';
                        return;
                    }
                    if ((index <= 3 && index > 0) || index === columns.length - 1) {
                        return;
                    }
                    switch (column.property) {
                        case "recharge":
                            sums[index] = this.sumMap.recharge;
                            break;
                        case "cash":
                            sums[index] = this.sumMap.cash;
                            break;
                        case "giftOrder":
                            sums[index] = this.sumMap.giftOrder;
                            break;
                        case "giftIncome":
                            sums[index] = this.sumMap.giftIncome;
                            break;
                        case "systemGiftIncome":
                            sums[index] = this.sumMap.systemGiftIncome;
                            break;
                        case "ballBet":
                            sums[index] = this.sumMap.ballBet;
                            break;
                        case "ballRevert":
                            sums[index] = this.sumMap.ballRevert;
                            break;
                        case "ballResult":
                            sums[index] = this.sumMap.ballResult;
                            break;
                        case "selfRebate":
                            sums[index] = this.sumMap.selfRebate;
                            break;
                        case "subRebate":
                            sums[index] = this.sumMap.subRebate;
                            break;
                        case "systemRebatePay":
                            sums[index] = this.sumMap.systemRebatePay;
                            break;
                        case "gameCenterIncome":
                            sums[index] = this.sumMap.gameCenterIncome;
                            break;
                        case "exchange":
                            sums[index] = this.sumMap.exchange;
                            break;
                        case "exchangeBack":
                            sums[index] = this.sumMap.exchangeBack;
                            break;
                        case "goodsPay":
                            sums[index] = this.sumMap.goodsPay;
                            break;
                        case "transfer":
                            sums[index] = this.sumMap.transfer;
                            break;
                        case "transferCancel":
                            sums[index] = this.sumMap.transferCancel;
                            break;
                        case "collect":
                            sums[index] = this.sumMap.collect;
                            break;
                        case "buyViewPoint":
                            sums[index] = this.sumMap.buyViewPoint;
                            break;
                        case "sellViewPoint":
                            sums[index] = this.sumMap.sellViewPoint;
                            break;
                        case "refundViewPoint":
                            sums[index] = this.sumMap.refundViewPoint;
                            break;
                        case "returnViewPoint":
                            sums[index] = this.sumMap.returnViewPoint;
                            break;
                        case "systemViewPointIncome":
                            sums[index] = this.sumMap.systemViewPointIncome;
                            break;
                        case "activityCostRebate":
                            sums[index] = this.sumMap.activityCostRebate;
                            break;
                        case "activityInviteRebate":
                            sums[index] = this.sumMap.activityInviteRebate;
                            break;
                        default:
                            sums[index] = "N/A";
                            break;
                    }
                });
                return sums;
            }
        },
        created: function () {
            this.pageData();
        }
    });
</script>
<!--#
}
#-->